package com.henry.service;

import com.henry.feign.service.FeignProducrService;
import com.henry.feign.service.FeignUserService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.henry.dao.OrderMapper;
import com.henry.pojo.Order;
import com.henry.service.OrderService;
import org.springframework.transaction.annotation.Transactional;

@Service("aa")
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService{

    @Autowired
    private FeignProducrService feignProducrService;

    @Autowired
    private FeignUserService feignUserService;

    /**
     * 创建订单
     *  1.生成订单并插入
     *  2.扣减库存
     *  3.扣减余额
     */
//    @Transactional
    @GlobalTransactional
    public void create() {

        //1. 生成订单
        Order order = new Order();
        order.setUserId(1);
        order.setProductId(1);
        order.setNumber(1);
        order.setPrice(Double.parseDouble("5888"));
        order.setStatus("0");
        baseMapper.insert(order);

        //2.扣减库存
        feignProducrService.update(1,1);

        int i = 10 / 0;
        //3.扣减余额
        feignUserService.update(1,Double.parseDouble("5888"));

    }
}
